<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.jstl.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<html>
<head>
    <title>JSTL的基本使用</title>
</head>
<body>
    <%
        List<User> users = new ArrayList<>();
        User u1 = new User("李白",28);
        users.add(u1);
        User u2 = new User("杜甫",18);
        users.add(u2);
        User u3 = new User("高适",32);
        users.add(u3);
        pageContext.setAttribute("userList",users);
        pageContext.setAttribute("lb",u1);
    %>
  <h2>表达式标签</h2>
    c:out<br/>
    <c:out value="${lb}" default="default_test"/>
    <br/>
    <c:out value="${lb}" >
        def_test
    </c:out>
    <br/>
     <c:out value="${lb.username}"/> <%--====等效${lb.username}--%>
     <br/>
     c:set
    <br/>
     <c:set var="coures" value="Java Web"/>
      <c:out value="${coures}"/>
     <br/>
      <c:set var="coures2">
           企业后端开发技术
      </c:set>
      ${coures2}
       <br/>
       <c:set value="123456" target="${lb}" property="password" />
       ${lb}
       <br/>
        <c:set target="${lb}" property="mobile" >
            10086
        </c:set>
         ${lb}
      <br/>
      c:remove
      <br/>
      <c:remove var="coures2"/>
      ${coures2}
<%--    java的try catch--%>
    <%
    try{

    }catch (Exception e){

    }
    %>
    <br/>
    <c:catch var ="catchException">
        <% int x = 5/0;%>
    </c:catch>

    <c:if test = "${catchException != null}">
        <p>异常为 : ${catchException} <br />
            发生了异常: ${catchException.message}</p>
    </c:if>

    <h2>URL相关标签 </h2>
   c:import
   <br/>
   <c:import url="/MydoGet">
       <c:param name="test" value="www.baidu.com"/>
   </c:import>
   <br/>
    c:url
    <br/>
    <c:url value="MydoGet" var="myurl">
        <c:param name="test" value="www.qq.com"  />
    </c:url>
    <br/>
<%--    http://localhost:8080/wk11_d2_jstl_project_war/MydoGet?test=www.qq.com--%>
    <a href="<c:out value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/${myurl}"/>"> myurl </a>
    <br/>
<h2>流程控制标签 </h2>

<%
    if(5>3){

    }else {

    }
%>
    c:if:
    <br/>
    <c:if test="${userList.size()>0}" var="listNotIsEmpty" />
    userList是否有元素：${listNotIsEmpty}
    <br/>
    <c:if test="${not empty userList&&userList.size()>0}" var="b1" >
        ${userList.get(0).username}
    </c:if>
    <br/>
<br/>
 c:choose
    <br/>
    <%
        int a=10;
        switch (a){
            case 1:
                break;
            case 2:
                break;
            default:
                break;
        }
 %>

    <%request.setAttribute("score", "75"); %>
    <c:choose>
        <c:when test="${score>=90}">优秀</c:when>
        <c:when test="${score>=80&&score<90}">良好</c:when>
        <c:when test="${score>=70&&score<80}">中等</c:when>
        <c:when test="${score>=60&&score<70}">及格</c:when>
        <c:otherwise>不及格</c:otherwise>
    </c:choose>
<h2>循环标签</h2>
    c:forEach：
    <br/>

    <table  style="border:1px solid gray;">
        <th >
        <td>序号</td>
        <td>姓名</td>
        <td>年龄</td>
        </th>
        <c:forEach items="${userList}" var="item" varStatus="status">
            <tr >
                <td>${status.count}</td>
                <td>${item.username}</td>
                <td>${item.age}</td>
            </tr>
        </c:forEach>
    </table>




</body>
</html>
